#include "Rectangle.h"

#ifndef IO_HEADER
    #include <iostream>
    #define IO_HEADER
#endif

Rectangle::Rectangle(int Width, int Height)
{
    Surface = SDL_CreateRGBSurface(SDL_HWSURFACE, Width, Height, 32, 0, 0, 0, 0);
    if(! Surface) std::cout << "Erreur lors de la création de la surface" << std::endl;
}

Rectangle::Rectangle(int Width, int Height, int _X, int _Y)
{
    Surface = SDL_CreateRGBSurface(SDL_HWSURFACE, Width, Height, 32, 0, 0, 0, 0);
    if(! Surface) std::cout << "Erreur lors de la création de la surface" << std::endl;

    X = _X;
    Y = _Y;
}

Rectangle::~Rectangle()
{
    SDL_FreeSurface(Surface);
}

void Rectangle::Fill(SDL_Surface* Screen, Uint8 R, Uint8 G, Uint8 B)
{
    int result = SDL_FillRect(Surface, NULL, SDL_MapRGB(Screen->format, R, G, B));
    if(result < 0) std::cout << "Erreur lors du remplissage de la surface" << std::endl;
}

void Rectangle::Blit(SDL_Surface* Screen)
{
    SDL_Rect Position;
    Position.x = X;
    Position.y = Y;

    SDL_BlitSurface(Surface, NULL, Screen, &Position);
}
